package com.chao.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.chao.utils.RabbitMqUtils.*;

@Configuration
public class FanoutConfiguration {

    // /**
    //  * fanout 交换机声明
    //  *
    //  * @return
    //  */
    // @Bean
    // public FanoutExchange FanoutExchange() {
    //     return ExchangeBuilder.fanoutExchange(FANOUT_EXCHANGES).build();
    // }
    //
    // /**
    //  * 队列声明
    //  *
    //  * @return
    //  */
    // @Bean
    // public Queue fanoutQueueOne() {
    //     return new Queue(FANOUT_QUEUE_ONE);
    // }
    //
    // @Bean
    // public Queue fanoutQueueTwo() {
    //     return new Queue(FANOUT_QUEUE_TWO);
    // }
    //
    // /**
    //  * 绑定交换机和队列
    //  *
    //  * @return
    //  */
    // @Bean
    // public Binding fanoutBinding3() {
    //     return BindingBuilder.bind(fanoutQueueOne()).to(FanoutExchange());
    // }
    //
    // // 第二种绑定方法 传参
    // @Bean
    // public Binding fanoutBinding4(Queue fanoutQueueTwo, FanoutExchange fanoutExchange) {
    //     return BindingBuilder.bind(fanoutQueueTwo).to(fanoutExchange);
    // }


    /**
     * 1、direct 交换机声明
     *
     * @return
     */
    @Bean
    public DirectExchange DirectExchangeCallback() {
        return ExchangeBuilder.directExchange(DIRECT_EXCHANGES_CALLBACK).build();
    }

    /**
     * 2、队列声明
     *
     * @return
     */
    @Bean
    public Queue directQueueOne() {
        return new Queue(DIRECT_QUEUE_ONE);
    }
    @Bean
    public Queue directQueueTow() {
        return new Queue(DIRECT_QUEUE_TWO);
    }

    /**
     * 3、绑定交换机和队列
     *
     * @return
     */
    @Bean
    public Binding directBindingOne() {
        return BindingBuilder.bind(directQueueOne()).to(DirectExchangeCallback()).with("one");
    }

    @Bean
    public Binding directBindingTow() {
        return BindingBuilder.bind(directQueueTow()).to(DirectExchangeCallback()).with("tow");
    }

    // // 第二种绑定方法 传参
    // @Bean
    // public Binding directBindingTow(Queue directQueueTow, DirectExchange DirectExchangeCallback) {
    //     return BindingBuilder.bind(directQueueTow).to(DirectExchangeCallback).with("two");
    // }


    /**
     * 1、fanout 交换机声明
     *
     * @return
     */
    @Bean
    public DirectExchange directExchange() {
        // return new FanoutExchange(FANOUT_EXCHANGES);
        return ExchangeBuilder.directExchange(DIRECT_EXCHANGES).build();
    }

    /**
     * 2、队列声明
     *
     * @return
     */
    @Bean
    public Queue emailDirect() {
        return new Queue(CG_EMAIL_DIRECT);
    }

    /**
     * 3、绑定交换机和队列
     *
     * @return
     */
    @Bean
    public Binding directBinding() {
        return BindingBuilder.bind(emailDirect()).to(directExchange()).with("");
    }
}

